﻿using Microsoft.Phone.Tasks;
using SMARTMobile.WinPhone;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;

namespace SMARTMobile.ViewModels
{
    public partial class HoTroViewModel : ViewModelBase
    {
        PhotoChooserTask selectphoto = null;
        private BitmapImage _imageSource;

        public HoTroViewModel()
        {

        }

        public BitmapImage ImageSource
        {
            get 
            {
                return this._imageSource; 
            }
            set 
            {
                _imageSource = value;
                base.RaisePropertyChanged("ImageSource");
            }
        }

        #region Commands

        public ICommandRoute OpenImageCommand { get; private set; } 
        public ICommandRoute SendErrorCommand { get; private set; }
        public ICommandRoute ExitCommand { get; private set; }       

        #endregion

        #region Command Action Handlers

        private void ExecuteOpenImageCommand(object commandParams)
        {
            this.selectphoto = new PhotoChooserTask();
            this.selectphoto.Completed += selectphoto_Completed;
            this.selectphoto.Show();
        }

        private void ExecuteSendErrorCommand(object commandParams)
        {

        }

        private void ExecuteExitCommand(object commandParams)
        {
            this.ExitCommand.RaiseCanExecuteChanged(true);
            base.PageNavigation.Navigate("Main");
        }

        #endregion

        #region Method

        private void selectphoto_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                BitmapImage image = new BitmapImage();
                image.SetSource(e.ChosenPhoto);
                this.ImageSource = image; 
            }
        }

        #endregion
    }
}
